package com.mallcloud.mall.mall.api.entity.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mallcloud.mall.common.core.constant.enums.mall.PointsCouponEnum;
import com.mallcloud.mall.common.core.exception.FailException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

@ApiModel(value = "MallPointsCouponVO", description = "积分券")
@Data
@ToString
@EqualsAndHashCode(callSuper = false)
public class MallPointsCouponVO implements Serializable {
    private static final long serialVersionUID = 1L;

	@ApiModelProperty("临时唯一标识")
	private String tempId;
	public void setTempId(String tempId) {
		this.tempId = tempId;
		String[] split = tempId.split(StrUtil.COMMA);
		if(split.length != 2){
			throw new FailException("券tempId格式错误");
		}
		this.type = split[0];
		this.scheduleId = split[1];
	}

	@ApiModelProperty(value = "档期码")
	private String scheduleId;

	/**
	 * {@link PointsCouponEnum.TypeEnum}
	 */
	@ApiModelProperty(value = "券种类")
	private String type;

    @ApiModelProperty(value = "券名称")
    private String name;

    @ApiModelProperty(value = "券可兑换金额")
    private BigDecimal redeemMoney;

	/**
	 * 兑换券单位是积分
	 * 购买券单位是元
	 */
	@ApiModelProperty(value = "售价")
    private BigDecimal salePrice;

    @ApiModelProperty(value = "开始日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date startTime;

    @ApiModelProperty(value = "结束日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date endTime;

	@ApiModelProperty(value = "已售数量")
	private Integer saleNum;

	@ApiModelProperty(value = "剩余数量")
	private Integer leftNum;

    @ApiModelProperty(value = "剩余比例")
    private Integer leftPercent;

    // 拓展 --------------
    @ApiModelProperty(value = "收券规则")
    private String rule;

	/**
	 * {@link PointsCouponEnum.PurposeEnum}
	 */
	@ApiModelProperty("券用途")
	private Integer purpose;

	@ApiModelProperty(value = "券用途名称")
	private String purposeName;
}
